package com.codingfuture.erp_system.web.controller;

import com.codingfuture.erp_system.dto.PageData;
import com.codingfuture.erp_system.entity.StoreAlert;
import com.codingfuture.erp_system.service.StockAlertService;
import com.codingfuture.erp_system.util.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("/v2")
@RestController
public class StockAlertController {

    @Autowired
    private StockAlertService stockAlertService;

    @GetMapping("/storealert")
    public Result findByAll(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int rows, HttpSession session) {
        session.getAttribute("goodname");
        session.getAttribute("num");
        Page<Object> startPage = PageHelper.startPage(page, rows);
        List<StoreAlert> list = stockAlertService.findByAll();
        PageData<StoreAlert> data = new PageData<>(list, startPage.getTotal());
        return Result.ok(data);
    }


    @PostMapping("/sms")
    public Result findBySms() throws Exception {
        stockAlertService.findBySms();
        return Result.ok();
    }

}
